package cn.xxm.activiti7_workflow;

import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;


@SpringBootTest
public class Part4_Task {

    @Autowired
    private TaskService taskService;

    //任务查询
    @Test
    public void getTasks(){
        List<Task> list = taskService.createTaskQuery().list();
        for(Task tk : list){
            System.out.println("Id："+tk.getId());
            System.out.println("Name："+tk.getName());
            System.out.println("Assignee："+tk.getAssignee());
        }
    }

    //查询我的代办任务
    @Test
    public void getTasksByAssignee(){
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee("bajie")
                .list();
        for(Task tk : list){
            System.out.println("Id："+tk.getId());
            System.out.println("Name："+tk.getName());
            System.out.println("Assignee："+tk.getAssignee());
        }

    }

    /**
     * 功能描述: 任务完成之后,act_ru_task,act_ru_execution,act_ru_identitylink  表中相关的数据会被清空,
     *          然后曾经的记录会保存到历史表中,
     *          这样保证任务的执行效率是很高的,这几张表数据不会随着时间的推移越来越多
     *          迁移到的历史表 act_hi_taskinst,act_hi_procinst,act_hi_identitylink,act_hi_actinst
     * @param:
     * @return:
     * @author:
     * @date: 2020/10/1 14:27
     */
    @Test
    public void completeTask(){
        //d270adb0-0332-11eb-beeb-00ff3940678f  bajie
        //e9b43ca2-0337-11eb-9aed-00ff3940678f  wukong
        taskService.complete("2d4d60a8-03bd-11eb-b0e0-00ff3940678f");
        System.out.println("完成任务");

    }

    //拾取任务
    @Test
    public void claimTask(){
        Task task = taskService.createTaskQuery().taskId("45caac21-03bb-11eb-ba9a-00ff3940678f").singleResult();
        taskService.claim("45caac21-03bb-11eb-ba9a-00ff3940678f","wukong");
    }

    //归还与交办任务
    @Test
    public void setTaskAssignee(){
        Task task = taskService.createTaskQuery().taskId("039381d5-03b3-11eb-9302-00ff3940678f").singleResult();
        taskService.setAssignee("039381d5-03b3-11eb-9302-00ff3940678f","null");//归还候选任务
        taskService.setAssignee("039381d5-03b3-11eb-9302-00ff3940678f","wukong");//交办
    }



}
